package formServlets;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.ibm.icu.util.Calendar;

public class UserPersonalInfo implements Serializable {
	  @PrimaryKey
	    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	    private Key key;

	   
	    @Persistent
	    private String Userid;       //unique userid or username that is used for signing in

	    @Persistent
	    private String firstName;    
	    
	    @Persistent
	    private String lastName;
	    
	    @Persistent
	    private String gender;
	    
	    @Persistent
	    private int yearBorn;       // date of birth to calculate age
	    
	    @Persistent
	    private String citizenship;
	    


	    public UserPersonalInfo( String Userid,String firstName, String lastName,String gender,int yearBorn, String citizenship)
	    {
	     this.Userid=Userid;
	     this.firstName=firstName;
	     this.lastName=lastName;
	     this.gender=gender;
	     this.yearBorn=yearBorn;
	     this.citizenship=citizenship;
	    }

	    public Key getKey() {
	        return key;
	    }

	    public String getUserid() {
	        return Userid;
	    }

	    public String getFirstName() {
	        return firstName;
	    }

	    public String getLastName() {
	        return lastName;
	    }

	    public String getGender() {
	        return gender;
	    }

	    public int getDOB() {
	        return yearBorn;
	    }
	    
	    public Integer getAge() {
	   	 Calendar currentDate = Calendar.getInstance();
		   SimpleDateFormat year= 
		    new SimpleDateFormat("yyyy");
		   SimpleDateFormat month= 
			    new SimpleDateFormat("MM");
		   SimpleDateFormat day= 
			    new SimpleDateFormat("dd");
		  String yr = year.format(currentDate.getTime());
		  String mon= month.format(currentDate.getTime());
		  String date= day.format(currentDate.getTime());
		  System.out.println("mm/dd/yyyy: "+mon+"/"+date+"/"+yr);
		  int yyyy=1987; // extract data from date field according to the format
		  int m=9;
		  int d=7;
		  int age=0;
		  if(Integer.parseInt(mon)<m)
		   age= Integer.parseInt(yr)-yyyy-1;
		  else
			  if(Integer.parseInt(mon)>m)
				   age= Integer.parseInt(yr)-yyyy;
			  else
				  if(Integer.parseInt(mon)==m)
				  {
					  if(Integer.parseInt(date)<d)
						   age= Integer.parseInt(yr)-yyyy-1;
						  else
							  if(Integer.parseInt(date)>d)
								   age= Integer.parseInt(yr)-yyyy;
				  }
		 System.out.println("age="+age);
		 return age;
	    }
	    
	    public String getCitizenShip()
	    {
	    	return(this.citizenship);
	    }
	   
	    public void setUsername(String userid) {
	        this.Userid=userid;
	    }

	    public void setFirstName(String firstName) {
	        this.firstName=firstName;
	    }
	    
	    public void setLastName(String lastName) {
	        this.lastName=lastName;
	    }
	    
	    public void setGender(String Gender) {
	        this.gender=Gender;
	    }
	
	    public void setDOB(int yearBorn) {
	        this.yearBorn=yearBorn;
	    }
	    
	    public void setCitizenShip(String citizenship) {
	        this.citizenship=citizenship;
	    }
}
